package com.itheima.controller;

import com.itheima.dto.RequestParams;
import com.itheima.service.SearchService;
import com.itheima.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("/list")
    public PageResult search(@RequestBody RequestParams requestParams) throws IOException {
        return searchService.search(requestParams);
    }

    /**
     * 创建ES表
     *
     * @throws IOException
     */
    @PostMapping("/initIndex")
    public void InitializeESIndex() throws IOException {
        searchService.initializeESIndex();
    }

    /**
     * 导入ES表内数据，从MySql中
     *
     * @throws IOException
     */
    @PostMapping("/initData")
    public void InitializeESData() throws IOException {
        searchService.initializeESData();
    }
}
